<template>
  <div class="singer">
    <!-- 头部筛选 -->
    <div class="singer-top">
      <Singertags :tagitem="langType" @selectTag="selectTag"></Singertags>
      <Singertags :tagitem="singerType" @selectTag="selectTag"></Singertags>
      <Singertags
        :tagitem="selectByInitials"
        @selectTag="selectTag"
      ></Singertags>
    </div>
    <!-- 歌手列表 -->
    <div class="siger-list flex">
      <Singeritem
        v-for="(item, index) in singerList"
        :key="index"
        :singer="item"
      ></Singeritem>
    </div>
    <Loading v-show="!isReady"/>
  </div>
</template>

<script>
import Singertags from "@/components/Singertags";
import Singeritem from "@/components/Singeritem";
import Loading from "@/components/Loading";
import {
  langType,
  singerType,
  selectByInitials,
} from "@/common/singer_data.js";
import { getSingerList } from "@/network/singer";
export default {
  name: "Singer",
  data() {
    return {
      langType,
      singerType,
      selectByInitials,
      singerList: [],
      type: "-1",
      initial: "-1",
      area: "7",
      isReady: true
    };
  },
  created() {
    this.getSinger(this.type, this.area, this.initial);
  },
  methods: {
    selectTag(tag, tagtype) {
      console.log(tag);
      console.log(tagtype);
      this.isReady = false;
      setTimeout(() => {
        this.isReady = true;
      }, 3000);
      switch (tagtype) {
        case "语种":
          this.area = tag;
          break;
        case "分类":
          this.type = tag;
          break;
        default:
          this.initial = tag;
      }
      this.getSinger(this.type, this.area, this.initial);
    },
    //获取歌手列表
    getSinger(type, area, initial) {
      this.singerList = [];
      getSingerList("/artist/list", {
        limit: 30,
        type,
        initial,
        area,
      }).then((res) => {
        console.log(res);
        this.singerList = res.artists;
      });
    },
  },
  components: {
    Singertags,
    Singeritem,
    Loading
  },
};
</script>

<style scoped lang="less">
.singer {
  .siger-list {
    margin-top: 20px;
  }
}
</style>